<%@page import="com.dfhc.util.CryptoHelper"%>
<%@page import="org.quickbundle.orgauth.rmpartytype.util.IRmPartyTypeConstants"%>
<%@page import="com.dfhc.util.StringHelper"%>
<%@ page import="org.quickbundle.orgauth.rmparty.util.IRmPartyConstants" %>
<%@page import="com.dfhc.util.CryptoHelper"%>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />

<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %>
<title> </title>

<%@ taglib uri="/dfhc" prefix="dfhc" %>
</head>
<body>


<article class="page-container">

<!-- 定制项目参照 -->
<dfhc:div templateId="h_ui_div_reference" id="partyTypeIdContent">
	<form name="searchForm" id="searchForm" action="">
	<dfhc:div templateId="h_ui_div_search">
		<%-- <dfhc:input templateId="h_ui_search_input" placeholder="输入xxx、xxx、xxx" id="" name="searchName"/>
		<dfhc:button templateId="h_ui_search_button" id="" name="" onclick="javascript:_searchData($('#moduleIdTable').DataTable());" /> --%>
	</dfhc:div>
	</form>
    	<dfhc:table templateId="table_h_ui" id="partyTypeIdTable" >    	
		<dfhc:thead>
			<dfhc:tr> 
			
				<dfhc:th  width="25" >
				   <dfhc:checkbox name="allId" /> &nbsp;&nbsp;序号
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("bs_keyword")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("name")%> </dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("icon")%> </dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("description")%> </dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("is_custom_attribute")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("is_allow_hanging_user")%> </dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("is_allow_hanging_role")%></dfhc:title>
				</dfhc:th>
				
			</dfhc:tr>
    	   </dfhc:thead>			
	</dfhc:table>           
</dfhc:div>

	<form action="" method="post" class="form form-horizontal" id="form-add">
	   <input type="hidden" id="id" name="id" value="${bean.id}">
							
		<dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=StringHelper.replaceAll(IRmPartyConstants.TABLE_COLUMN_CHINESE.get("party_type_id"),"ID","")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input templateId="h_ui_input" type = "hidden" value="${bean.party_type_id}" placeholder='<%=StringHelper.replaceAll("点击选择"+IRmPartyConstants.TABLE_COLUMN_CHINESE.get("party_type_id"),"ID","")%>' id="partyTypeId" name="party_type_id" readonly="true"/>
	    	<dfhc:input templateId="h_ui_input"    style="display:none" value="" placeholder='<%=StringHelper.replaceAll("点击选择"+IRmPartyConstants.TABLE_COLUMN_CHINESE.get("party_type_id"),"ID","")%>'  id="partyTypeIdName" name="partyTypeIdName" readonly="true" />			
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("old_party_id")%>：</dfhc:label>	    
	    <dfhc:div templateId="h_ui_div_label_div" >	         
			<dfhc:input templateId="h_ui_input" class="input-text"  value="${bean.old_party_id}"  id="old_party_id"  placeholder=""  name="old_party_id" />			
	 	</dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("name")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input templateId="h_ui_input" class="input-text"  value="${bean.name}"  id="name"  placeholder=""  name="name" />			
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("is_inherit")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<input type="checkbox"   name="is_inherit" id="checkboxName" value="${bean.is_inherit}" />	
	    </dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("email")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input  templateId="h_ui_input" type="text"   name="email" id="email" value="${bean.email}" />	
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("description")%>：</dfhc:label>	    
	    <dfhc:div templateId="h_ui_div_label_div" >	         
			<dfhc:textarea value="" id="description"  name="description"  templateId="h_ui_textarea" >${bean.description}</dfhc:textarea>
	 	</dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("custom1")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input  templateId="h_ui_input" type="text"   name="custom1" id="custom1" value="${bean.custom1}" />	
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("custom2")%>：</dfhc:label>	    
	    <dfhc:div templateId="h_ui_div_label_div" >	         
			<dfhc:input  templateId="h_ui_input"  value="${bean.custom2}" id="custom2"  name="custom2"   />
	 	</dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("custom3")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input  templateId="h_ui_input" type="text"   name="custom3" id="custom3" value="${bean.custom3}" />	
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("custom4")%>：</dfhc:label>	    
	    <dfhc:div templateId="h_ui_div_label_div" >	         
			<dfhc:input  templateId="h_ui_input"  value="${bean.custom4}" id="custom4"  name="custom4"  />
	 	</dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("custom5")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input  templateId="h_ui_input" type="text"   name="custom5" id="custom5" value="${bean.custom5}" />	
	    </dfhc:div>
	  </dfhc:div>
	  
	  
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:div templateId="h_ui_div_pop_up_button">
				<dfhc:button templateId="h_ui_submit_button" />
				<dfhc:button templateId="h_ui_cancel_button" onclick="cancel();" />
				<dfhc:button templateId="h_ui_reset_button" onclick="reset();" />
			</dfhc:div>
		</dfhc:div>
	</form>
</article>



<script type="text/javascript">
var _table;
var newusrl=getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/RmPartyByHUI")%>';
$(function(){
	<c:if test="${not empty bean}"> 
	if("${bean.is_inherit}" != null && "${bean.is_inherit}" != "" && "${bean.is_inherit}" != "0"){
		$('#checkboxName').prop("checked",true);
	}
	</c:if>
	
	//点击选择定制项目
    $("#partyTypeId").on('focus',function(){
    	$("#partyTypeId").show();
    	$("#partyTypeIdName").hide();
    	var partyTypeIdObj = $("#partyTypeId");
    	var partyTypeIdContentObj = $("#partyTypeIdContent");
    	var partyTypeIdOffset = partyTypeIdObj.offset();
    	var top = (partyTypeIdOffset.top + partyTypeIdObj.outerHeight()-partyTypeIdContentObj.outerHeight())+"px";    	
    	$("#partyTypeIdContent").css({
    	left:partyTypeIdOffset.left+"px",
    	top:(partyTypeIdOffset.top +partyTypeIdObj.outerHeight())+"px",
    	display:"block",
    	width:(partyTypeIdObj.outerWidth()-3)+"px",    	    
    	}).slideDown("fast");
    	
    	$("body").bind("mousedown",function(){
    	   if(!(event.target.id =="partyTypeIdContent" || $(event.target).parents("#partyTypeIdContent").length>0)){
    	   $("#partyTypeIdContent").css({
    		left:0,
    		top:0,
    		display:"none",
    		width:0
    	   }).fadeOut("fast");
    	   }
    	});
    });
    $("#partyTypeIdName").on('focus',function(){
    	$("#partyTypeId").show();
    	$("#partyTypeIdName").hide();
    	var partyTypeIdObj = $("#partyTypeId");
    	var partyTypeIdContentObj = $("#partyTypeIdContent");
    	var partyTypeIdOffset = partyTypeIdObj.offset();
    	var top = (partyTypeIdOffset.top + partyTypeIdObj.outerHeight()-rmPartyTypeContentObj.outerHeight())+"px";    	
    	$("#rmPartyTypeContent").css({
    	left:partyTypeIdOffset.left+"px",
    	top:(partyTypeIdOffset.top +partyTypeIdObj.outerHeight())+"px",
    	display:"block",
    	width:(partyTypeIdObj.outerWidth()-3)+"px",    	    
    	}).slideDown("fast");
    	
    	$("body").bind("mousedown",function(){
    	   if(!(event.target.id =="partyTypeIdContent" || $(event.target).parents("#partyTypeIdContent").length>0)){
    	   $("#partyTypeIdContent").css({
    		left:0,
    		top:0,
    		display:"none",
    		width:0
    	   }).fadeOut("fast");
    	   }
    	});
    });
	
    table1 = $('#partyTypeIdTable').dataTable({	
	     dom: 'Zlfrtip',	   		
		 ajax : function(data, callback, settings) {
		       var param =  splitParameter(data); 
              $.ajax({  
                      type: "GET",  
                      url: getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/RmPartyTypeByHUI/ajaxList")%>',  
                      cache : false,  //禁用缓存  
                      data:param,   
                      dataType: "json",  
                      success: function(result) {  
                              //异常判断与处理  
                              if (result.status=='0') {  
                                  alert(result.message);  
                                  return;  
                              }  
                              //封装返回数据  
                              var returnresult= {};  
                              returnresult.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回  
                              returnresult.recordsTotal = result.recordsTotal;//总记录数  
                              returnresult.recordsFiltered = result.recordsTotal;//后台不实现过滤功能，每次查询均视作全部结果  
                              returnresult.data = result.data;
                              //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染  
                              //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕  
                              callback(returnresult);  
                              //更新总记录数
                              $("#totalRecodSpan").html('共有数据：<strong>'+result.recordsTotal+'</strong> 条</span>');
                      },  
                      error: function(XMLHttpRequest, textStatus, errorThrown) {  
                          alert("查询失败");  
                      }  
                  });  
          },  
          "columns": [
            		  {
            		    "data":"id",
            		    "width":"50px",
            			"render":function(data,type,row,meta){
            			   var content='<input type="checkbox" name="allId" value="'+row.id+row.name+'"/>';
            			   return content; 
            			}
            		  },
            		  {"data":"bs_keyword"},
            		  {"data":"name"},
            		  {"data":"icon"},
            		  {"data":"description"},
            		  {"data":"is_custom_attribute",
            			  "defaultContent":"",
            			    render:function(data,type,row,meta){
            			    	var content;
            				   	if(row.is_custom_attribute!=null && row.is_custom_attribute!= ""){
            					    if(row.is_custom_attribute=='1'){
            					    	content = '是';
            					    }else{
            					    	content = '否';
            					    }			 
            				  }
            			    return content; 
            			  }
            		  },
            		  {"data":"is_allow_hanging_user",
            			  "defaultContent":"",
            			    render:function(data,type,row,meta){
            			    	var content;
            				   	if(row.is_allow_hanging_user !=null && row.is_allow_hanging_user != "" ){
            					    if(row.is_allow_hanging_user=='1'){
            					    	content = '是';
            					    }else{
            					    	content = '否';
            					    }			 
            				  }
            			    return content; 
            			  }
            		  },
            		  {"data":"is_allow_hanging_role",
            			  "defaultContent":"",
            			    render:function(data,type,row,meta){
            			    	var content;
            				   	if(row.is_allow_hanging_role !=null && row.is_allow_hanging_role != ""){
            				   		
            					    if(row.is_allow_hanging_role=='1'){
            					    	content = '是';
            					    }else{
            					    	content = '否';
            					    }			 
            				  }
            			    return content; 
            			  }
            		  }
            	]  				
	}); 
  //参照表格check box 绑定值变更
	table1.delegate($("td input[name=allId]"),"change",function(row){
	//判断用户是否选择
	var len = $('input[name="allId"]:checked').length;
	var count=0;
	var ids='';
	var dataId ;
	$('input[name="allId"]:checked').each(function(row){
     	
     	dataId =$(this).val().substring(0,19);
     	var dataname =$(this).val().substring(19);
     	$("#partyTypeIdName").val(dataname);
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=""
         	}
         	count++;
     	}
       });  
      
    
      if(count>1){
       alert("只能选择一条记录!");
       return;	
      }
      if(count==1){
    	//回填模块ID
    	
    	$("#partyTypeId").val(dataId);
    	$("#partyTypeId").hide();
    	
    	$("#partyTypeIdName").show();
    	//隐藏表格
    	$("#partyTypeIdContent").css({
    		left:0,
    		top:0,
    		display:"none",
    		width:0
    	   }).fadeOut("fast");
      }else if(count ==0){
        //回填模块ID
        $('#partyTypeIdName').val('');
    	$("#partyTypeId").val('');
      }    	   
	});

	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	
	
	$("#form-add").validate({
		rules:{
			bs_keyword:{			
			},
			name:{			
			},
			icon:{			
			},
			description:{			
			},
			is_custom_attribute:{			
			},
			is_allow_hanging_user:{			
			},
			is_allow_hanging_role:{			
			}
		},
 		messages: {
 			bs_keyword:{
	           },
	           name:{
	           },
	           icon:{
	           },
	           description:{
	           },
	           is_custom_attribute:{
	           },
	           is_allow_hanging_user:{
	           },
	           is_allow_hanging_role:{
	           }
	    },		
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			if($("input[type='checkbox']").is(':checked')){
				$('#checkboxName').val('1');
			}
			<c:if test="${empty bean}"> 
			var url = getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/RmPartyByHUI/insert")%>?jsguid='+$('#id').val();
			</c:if>
			<c:if test="${not empty bean}"> 
			if("${bean.is_inherit}" != null && "${bean.is_inherit}" != "" && "${bean.is_inherit}" != "0" ){
				$('#checkboxName').prop("checked",true);
			}
			var url = getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/RmPartyByHUI/update")%>?jsguid='+$('#id').val();
			</c:if>
			//提交成功关闭
			submitAjax(url,$("#form-add").serialize(),newusrl);
			/* window.location.href=newusrl; */
		}
	});
});
function submitAjax(url,param,successUrl){
 	//url后面自动带jsguid
	if(url.indexOf("jsguid")==-1){
		 if(url.indexOf("?")==-1){
			   url = url+"?jsguid="+__global_guid;
		 }else{
			   url = url+"&jsguid="+__global_guid;
		 }
	}
	//url 后面自动带csrf 编码
	if(!isStrEmpty($('#_csrfcode_').val())){
		if (url.indexOf("?") == -1) {
			url = url + "?_csrfcode_=" + $('#_csrfcode_').val();
		} else {
			url = url + "&_csrfcode_=" + $('#_csrfcode_').val();
		}
	}
 
	 $.ajax({
	    type:'post',//可选get
	    url:url,
	    data:param,//送评表的表格id属性值
	    dataType:'json',
	    async:false , //false为同步
	    success:function(data,status){
	      //更新csrf随机码
	      $("#_csrfcode_").val(data._csrfcode_);
		  if(data.status=="0"){
		  	  layer.msg(data.message,{icon:1,time:1000});
			  //alert(data.message);
			  return false;
	   	   }else{	   	      
	   		  alert(data.message);
	   		  layer.msg(data.message,{icon:1,time:1000});
	   		  if(!isStrEmpty(successUrl)){
	   		    window.location.href=successUrl;
	   		  }	   		  
	   		  return true;   		
	   	   }
		   	
	   },
	   error:function(xhr,s1,s2){
			var  message= xhr.responseText;
	    	var  json = jQuery.parseJSON(message);
	
			if($.trim(json.exception).length==0){
				alert('数据异常,请刷新页面重试');
			}else{
				alert(json.exception);
			}
			return false;			
	   }
	   });
}
function singleDelete(url){
	//判断是否选择
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择删除的记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
    //url 后面自动带csrf 编码
	if(!isStrEmpty($('#_csrfcode_').val())){
		if (newUrl.indexOf("?") == -1) {
			newUrl = newUrl + "?_csrfcode_=" + $('#_csrfcode_').val();
		} else {
			newUrl = newUrl + "&_csrfcode_=" + $('#_csrfcode_').val();
		}
	}
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: getRootPath()+newUrl,
			dataType: 'json',
			success: function(data){
				//$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				$('.table-sort').DataTable().ajax.reload();
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
	$('.table-sort').DataTable().ajax.reload();
}
function cancel(){
	window.location.href=getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/RmPartyByHUI")%>';
}
function reset(){
	$("#party_type_id").val('');
	$("#old_party_id").val('');
	$("#name").val('');
	$("#is_inherit").val('');
	$("#email").val('');
	$("#description").val('');
	$("#custom1").val('');
	$("#custom2").val('');
	$("#custom3").val('');
	$("#custom4").val('');
	$("#custom5").val('');
}
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
